package com.wht.bill.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.wht.bill.R;
import com.wht.bill.bean.AccountBean;


/**
 * 账户列表适配器
 */
public class AccountAdapter extends BaseQuickAdapter<AccountBean, BaseViewHolder> {


    public AccountAdapter() {
        super(R.layout.item_tally_account);
    }


    @Override
    protected void convert(BaseViewHolder helper, AccountBean item) {
        TextView tvTitle = helper.getView(R.id.title);

        if (item != null) {
            if (!TextUtils.isEmpty(item.accountType)) {
                tvTitle.setText(item.accountType);
                //设置图标
                switch (item.accountType) {
                    case "银行卡":
                        Glide.with(getContext())
                                .load(R.mipmap.ic_bank)
                                .into((ImageView) helper.getView(R.id.img));
                        break;
                    case "微信":
                        Glide.with(getContext())
                                .load(R.mipmap.ic_wechat)
                                .into((ImageView) helper.getView(R.id.img));
                        break;
                    case "支付宝":
                        Glide.with(getContext())
                                .load(R.mipmap.ic_ali)
                                .into((ImageView) helper.getView(R.id.img));
                        break;
                    case "现金":
                        Glide.with(getContext())
                                .load(R.mipmap.ic_money)
                                .into((ImageView) helper.getView(R.id.img));
                        break;
                    default:
                        Glide.with(getContext())
                                .load(R.mipmap.ic_other)
                                .into((ImageView) helper.getView(R.id.img));
                        break;
                }
            } else {
                tvTitle.setText(" ");
            }
            if (!TextUtils.isEmpty(item.outcome)) {
                helper.setText(R.id.money_out, "-" + item.outcome);
            } else {
                helper.setText(R.id.money_out, "-0.00");
            }
            if (!TextUtils.isEmpty(item.income)) {
                helper.setText(R.id.money_in, "+" + item.income);
            } else {
                helper.setText(R.id.money_in, "+0.00");
            }
            if (!TextUtils.isEmpty(item.bankNo)) {
                if (item.bankNo.length() > 4) {
                    helper.setText(R.id.code, "尾号" + item.bankNo.substring(item.bankNo.length() - 4));
                } else {
                    helper.setText(R.id.code, "尾号" + item.bankNo);
                }
            } else {
                helper.setText(R.id.code, "");
            }
            helper.setGone(R.id.code, TextUtils.isEmpty(item.bankNo));
        }
    }
}
